-
Notifications
You must be signed in to change notification settings - Fork 9
ci(gitleaks): add pre-commit hook, config with sealed-secrets allowlist, and tests #287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
coretl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please can we also have a test in tests that inserts a secret into the code base, runs tox -e pre-commit and checks the output?
A bit like this but for pre-commit:
python-copier-template/tests/test_example.py
Lines 226 to 238 in 9d544a5
| def test_pep8_naming(tmp_path: Path): | |
| code = """ | |
| myVariable = "foo" | |
| """ | |
| copy_project(tmp_path) | |
| run = make_venv(tmp_path) | |
| src_file = tmp_path / "src" / "python_copier_template_example" / "bad_example.py" | |
| with src_file.open("w") as stream: | |
| stream.write(code) | |
| with pytest.raises(AssertionError, match=r"N816 .*"): | |
| run("ruff check") |
|
Following is what I have done in the latest commit and have pushed it to this branch.
|
paths line in .gitleaks.toml to extend to all files|
Is the decision to only do this in YAML documented somewhere? I think we'll potentially miss things doing this? |
@wajidzahoor-dls @coretl is it possible to do the bootstapping at devcontainer build time instead of on first run of pre-commit? In my experience it takes a little while which can be an annoying interruption to the commit workflow. |
This is a good point. Probably the most egregious cases are going to have the secret in source code. But, this could increase false positives by quite a bit. |
Many of the false positives are usually SealedSecrets. The allow-list is scoped to YAML/YML to keep the initial change small and avoid deviating too much from gitleaks’ defaults. All of gitleaks’ built-in rules still run ( At the template level this can server as default, but on a per-repo basis we can expand the allow-list beyond YAML by commenting out the Worth noting: the allow-list is regex-based and may occasionally cause false positives or false negatives, but overall it reduces SealedSecrets noise while keeping baseline coverage intact. |
My bad, this was a misunderstanding on my part. I think I read the comment:
To imply that all rules are only applied to YAML rather than just the sealed secret part. Could you update that comment to be clearer? |
I think this should be doable. Maybe we could look at using copier.yml tasks to install pre-commit hooks right after the template is applied (if the repo is already initialized), or lean on .devcontainer so the bootstrap happens automatically when the dev environment is first created. We can create separate branch to explore this further as needed. |
Thank you for the suggestion. I’ve updated the comments in .gitleaks.toml for clarity. |
|
https://pre-commit.com/#pre-commit-install suggests |
Tested locally, and |
…emplate/.gitleaks.toml
2147b27 to
b683927
Compare

Summary
Ag…patterns), scoped to*.yml/*.yaml.pathsline in.gitleaks.tomlfile.How to test
I verified this change with:
This should include output from gitleaks, scanning for potential hardcoded secrets.
For local testing, I used:
Depending on your environment, testing may happen differently:
tox -e pre-commit)Manual spot checks
Secret detection
Allowlist works (YAML only)
Ag…token in a.yaml/.ymlfile → should be allowlisted.Notes
pathsline in.gitleaks.tomlhttps://github.com/gitleaks/gitleaks